
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> rm(list = ls())
> library(igraph)

Attaching package: ‘igraph’

The following objects are masked from ‘package:stats’:

    decompose, spectrum

The following object is masked from ‘package:base’:

    union

> library(tidygraph)

Attaching package: ‘tidygraph’

The following object is masked from ‘package:igraph’:

    groups

The following object is masked from ‘package:stats’:

    filter

> library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:igraph’:

    as_data_frame, groups, union

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

> library(stargazer)

Please cite as: 

 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 

> 
> 
> #################33 Function to load and prepare the network data ###################
> load_and_prepare_network <- function(nodes_file, edgelist_file) {
+   # Load nodes
+   nodes <- readRDS(nodes_file)
+   
+   # Load the edgelist
+   edges <- readRDS(edgelist_file)
+   
+   # Create network using igraph
+   g <- graph_from_data_frame(d = edges, 
+                              vertices = nodes, 
+                              directed = TRUE)
+   
+   # Calculate in & out degree
+   V(g)$indegree <- degree(g, mode = 'in', loops = FALSE)
+   V(g)$outdegree <- degree(g, mode = 'out', loops = FALSE)
+   
+   # Convert to a tidy graph
+   g_tidy <- as_tbl_graph(g)
+   
+   return(g_tidy)
+ }
> 
> ########################## Function to get Top Legislators by Indegree Centrality ##########
> get_top_indegree_legislators <- function(g_tidy, type, output_file) {
+   nodes_tibble <- g_tidy %>% activate(nodes) %>% as_tibble()
+   
+   top_inDegree <- nodes_tibble %>%
+     arrange(desc(indegree)) %>%
+     select(name, state, party3, chamber) %>%
+     head(10)
+   
+   stargazer::stargazer(top_inDegree, type = type, 
+                        out = output_file, 
+                        summary = FALSE,
+                        row.names = FALSE)
+ }
> 
> 
> #################### Function to get Top Legislators by Outdegree Centrality ################
> get_top_outdegree_legislators <- function(g_tidy, type, output_file) {
+   nodes_tibble <- g_tidy %>% activate(nodes) %>% as_tibble()
+   
+   top_outDegree <- nodes_tibble %>%
+     arrange(desc(outdegree)) %>%
+     select(name, state, party3, chamber) %>%
+     head(10)
+   
+   stargazer::stargazer(top_outDegree, type = type, 
+                        out = output_file, 
+                        summary = FALSE,
+                        row.names = FALSE)
+ }
> 
> ###############################################################################################
> ################################   Apply the above functions  #################################
> # --------------------------------------------------------------------------------------------#
> # Get the top 10 legislators with the highest in and out degree in the follower network
> 
> nodes_file <- "processed_data/cleaned_nodes_R1.Rds"
> edgelist_file <- "processed_data/followers_edgelist_R1.Rds"
> 
> # Apply the 1st function to prepare the data
> g_tidy <- load_and_prepare_network(nodes_file, edgelist_file)
> 
> # Get top legislators by in degree centrality in the follower network
> get_top_indegree_legislators(g_tidy, type = "latex", "tables/descriptive/followers_inDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Danica Roem & Virginia & D & H \\ 
Brian P. Kavanagh & New York & D & S \\ 
Robert DeLeo & Massachusetts & D & H \\ 
Eric Lesser & Massachusetts & D & S \\ 
Nily Rozic & New York & D & H \\ 
Mary Gonzalez & Texas & D & H \\ 
Shevrin Jones & Florida & D & H \\ 
Rafael Anchia & Texas & D & H \\ 
Four Price & Texas & R & H \\ 
Carl Heastie & New York & D & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> 
> # Get top legislators by outdegree centrality in the follower network
> get_top_outdegree_legislators(g_tidy,  type = "latex", "tables/descriptive/followers_outDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Brian P. Kavanagh & New York & D & S \\ 
Mary Gonzalez & Texas & D & H \\ 
Eric Lesser & Massachusetts & D & S \\ 
Shevrin Jones & Florida & D & H \\ 
Alfred C. Carr Jr. & Maryland & D & H \\ 
Alan D. Clemmons & South Carolina & R & H \\ 
Victoria Neave & Texas & D & H \\ 
Sheryl Cole & Texas & D & H \\ 
Lori Ehrlich & Massachusetts & D & H \\ 
Sarah Davis & Texas & R & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> 
> 
> # --------------------------------------------------------------------------------------------#
> # Get the top 10 legislators with the highest in and out degree in the mentions network
> 
> nodes_file <- "processed_data/cleaned_nodes_R1.Rds"
> edgelist_file <- "processed_data/mentions_edgelist_R1.Rds"
> 
> # Apply the 1st function to prepare the data
> g_tidy <- load_and_prepare_network(nodes_file, edgelist_file)
> 
> # Get top legislators by in degree centrality in the mentions network
> get_top_indegree_legislators(g_tidy, type="latex", output_file="tables/descriptive/mentions_inDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Danica Roem & Virginia & D & H \\ 
Anna Eskamani & Florida & D & H \\ 
Robert DeLeo & Massachusetts & D & H \\ 
Carl Heastie & New York & D & H \\ 
Karen Spilka & Massachusetts & D & S \\ 
Andrea Stewart-Cousins & New York & D & S \\ 
Jamie Eldridge & Massachusetts & D & S \\ 
Dennis Bonnen & Texas & R & H \\ 
Mary Gonzalez & Texas & D & H \\ 
Shevrin Jones & Florida & D & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> 
> # Get top legislators by outdegree centrality in the mentions network
> get_top_outdegree_legislators(g_tidy,  type="latex", output_file="tables/descriptive/mentions_outDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Tram Nguyen & Massachusetts & D & H \\ 
Alan D. Clemmons & South Carolina & R & H \\ 
Brian P. Kavanagh & New York & D & S \\ 
Tami Gouveia & Massachusetts & D & H \\ 
Michelle Ciccolo & Massachusetts & D & H \\ 
Drew Springer Jr. & Texas & R & H \\ 
Christine Barber & Massachusetts & D & H \\ 
Carolyn Dykema & Massachusetts & D & H \\ 
Leslie Herod & Colorado & D & H \\ 
Cesar Blanco & Texas & D & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> # --------------------------------------------------------------------------------------------#
> 
> # Get the top 10 legislators with the highest in and out degree in the retweets network
> 
> nodes_file <- "processed_data/cleaned_nodes_R1.Rds"
> edgelist_file <- "processed_data/rt_edgelist_R1.Rds"
> 
> # Apply the 1st function to prepare the data
> g_tidy <- load_and_prepare_network(nodes_file, edgelist_file)
> 
> # Get top legislators by in degree centrality in the retweets network
> get_top_indegree_legislators(g_tidy, type="latex", output_file="tables/descriptive/retweets_inDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Danica Roem & Virginia & D & H \\ 
Melissa Hortman & Minnesota & D & H \\ 
Nily Rozic & New York & D & H \\ 
Joe Moody & Texas & D & H \\ 
Elijah Haahr & Missouri & R & H \\ 
Leslie Herod & Colorado & D & H \\ 
Brad Hoylman & New York & D & S \\ 
Jeff Leach & Texas & R & H \\ 
Shelly L. Hettleman & Maryland & D & S \\ 
Marc Korman & Maryland & D & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> 
> # Get top legislators by outdegree centrality in the retweets network
> get_top_outdegree_legislators(g_tidy,  type="latex", output_file="tables/descriptive/retweets_outDegree.tex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Cheryl Youakim & Minnesota & D & H \\ 
Leon Lillie & Minnesota & D & H \\ 
Chris Eaton & Minnesota & D & S \\ 
Lucy Weber & New Hampshire & D & H \\ 
Melissa Hortman & Minnesota & D & H \\ 
Fue Lee & Minnesota & D & H \\ 
Jason Isaacson & Minnesota & D & S \\ 
Susan Kent & Minnesota & D & S \\ 
Marjorie Porter & New Hampshire & D & H \\ 
Joelle Martin & New Hampshire & D & H \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Fri, Aug 25, 2023 - 05:27:08
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} c} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
FALSE \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
> 
> # --------------------------------------------------------------------------------------------#
> ###############################################################################################
> 
> proc.time()
   user  system elapsed 
  0.865   0.054   1.188 
